package com.morningstar.logger.config;

import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 队列线程数量配置
 * @author yls
 */
@Component
public class RabbitMqConfig {
    /**
     * @param configurer        配置
     * @param connectionFactory 链接工厂
     * @return 链接工厂
     */
    @Bean("containerFactory")
    public SimpleRabbitListenerContainerFactory factory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
                                                        ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        /*设置线程数*/
        factory.setConcurrentConsumers(5);
        /*最大线程数*/
        factory.setMaxConcurrentConsumers(20);
        configurer.configure(factory, connectionFactory);
        return factory;
    }
}
